package com.xdu.yunwufog.controller;

import com.google.gson.Gson;
import com.xdu.yunwufog.common.Result;
import com.xdu.yunwufog.connection.utils.ConnectionUtil;
import com.xdu.yunwufog.connection.utils.NettyTaskPool;
import com.xdu.yunwufog.connection.utils.ResultUtil;
import org.springframework.web.bind.annotation.*;
import java.util.*;


@RestController
public class MainController {

    /**
     * @Author voidwx
     * @Description 用户认证服务走的controller
     * @Date 16:53 2022/4/13
     * @Param [params]
     * @return com.xdu.yunwufog.common.Result
     **/
    @PostMapping("/userPWA")
    public Result userPWA(@RequestBody Map params) throws Exception{
        String jsonString = new Gson().toJson(params);
        String res = NettyTaskPool.submitTask(jsonString,ConnectionUtil.USER_AUTH);
        return ResultUtil.getResult(res);

    }

    /**
     * @Author voidwx
     * @Description userPWA的替代
     * @Date 16:53 2022/4/13
     * @Param [params]
     * @return com.xdu.yunwufog.common.Result
     **/
    @PostMapping("/userAuth")
    public Result userAuth(@RequestBody Map params) throws Exception{
        String jsonString = new Gson().toJson(params);
        String res = NettyTaskPool.submitTask(jsonString,ConnectionUtil.USER_AUTH);
        return ResultUtil.getResult(res);
    }
    /**
     * @Author voidwx
     * @Description 用户生物认证
     * @Date 17:02 2022/4/13
     * @Param [params]
     * @return com.xdu.yunwufog.common.Result
     **/
    @PostMapping("/bioAuth")
    public Result bioAuth(@RequestBody Map params) throws Exception{
        String paramsString = new Gson().toJson(params);
        paramsString += "finish";
        String res = NettyTaskPool.submitTask(paramsString,ConnectionUtil.BIO_AUTH);
        return ResultUtil.getResult(res);
    }
    /**
     * @Author voidwx
     * @Description 用户生物信息注册
     * @Date 17:03 2022/4/13
     * @Param [params]
     * @return com.xdu.yunwufog.common.Result
     **/
    @PostMapping("/bioRegister")
    public Result bioRegister(@RequestBody Map params) throws Exception{
        String paramsString = new Gson().toJson(params);
        paramsString += "finish";
        String res = NettyTaskPool.submitTask(paramsString,ConnectionUtil.BIO_REGISTER);
        return ResultUtil.getResult(res);
    }
    /**
     * @Author voidwx
     * @Description 活体检测
     * @Date 17:03 2022/4/13
     * @Param [params]
     * @return com.xdu.yunwufog.common.Result
     **/
    @PostMapping("/liveCheck")
    public Result liveCheck(@RequestBody Map params) throws Exception{
        String jsonString = new Gson().toJson(params);
        jsonString += "finish";
        String res = NettyTaskPool.submitTask(jsonString,ConnectionUtil.LIVE_CHECK);
        return Result.OK(res);
    }

}
